package cn.yuanqiao.web.controller.manage;

import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.manage.domain.YqdacategoryModel;
import cn.yuanqiao.manage.service.IYqdacategoryModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * manageController
 * 
 * @author yuanqiao
 * @date 2023-06-14
 */
@RestController
@RequestMapping("/manage/model")
public class YqdacategoryModelController extends BaseController
{
    @Autowired
    private IYqdacategoryModelService yqdacategoryModelService;

    /**
     * 查询manage列表
     */
    //@PreAuthorize("@ss.hasPermi('manage:MODEL:list")
    @Log(title = "查询门类模板列表", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(YqdacategoryModel yqdacategoryModel)
    {
        startPage();
        List<YqdacategoryModel> list = yqdacategoryModelService.selectYqdacategoryModelList(yqdacategoryModel);
        return getDataTable(list);
    }

    /**
     * 导出manage列表
     */
    //@PreAuthorize("@ss.hasPermi('manage:MODEL:export")
    @Log(title = "导出门类模板列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqdacategoryModel yqdacategoryModel)
    {
        List<YqdacategoryModel> list = yqdacategoryModelService.selectYqdacategoryModelList(yqdacategoryModel);
        ExcelUtil<YqdacategoryModel> util = new ExcelUtil<YqdacategoryModel>(YqdacategoryModel.class);
        util.exportExcel(response, list, "manage数据");
    }

    /**
     * 获取manage详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manage:MODEL:query")
    @Log(title = "获取应用模板详细信息", businessType = BusinessType.SELECT)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yqdacategoryModelService.selectYqdacategoryModelByID(id));
    }

    /**
     * 新增manage
     */
    //@PreAuthorize("@ss.hasPermi('manage:MODEL:add")
    @Log(title = "新增门类模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody YqdacategoryModel yqdacategoryModel)
    {
        return toAjax(yqdacategoryModelService.insertYqdacategoryModel(yqdacategoryModel));
    }

    /**
     * 修改manage
     */
    //@PreAuthorize("@ss.hasPermi('manage:MODEL:edit")
    @Log(title = "修改门类模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqdacategoryModel yqdacategoryModel)
    {
        return toAjax(yqdacategoryModelService.updateYqdacategoryModel(yqdacategoryModel));
    }

    /**
     * 删除manage
     */
    //@PreAuthorize("@ss.hasPermi('manage:MODEL:remove")
    @Log(title = "删除门类模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(yqdacategoryModelService.deleteYqdacategoryModelByIDs(IDs));
    }


    @Log(title = "获取门类模板树", businessType = BusinessType.SELECT)
    @GetMapping("/getcatemodeltree")
    public AjaxResult getcatemodeltree(YqdacategoryModel yqdacategorymodel){
        return success(yqdacategoryModelService.selectmatemodelTreeList(yqdacategorymodel));
    }
    /*初始化时使用,必须要有元数据方案的*/
    @Log(title = "获取门类模板的元数据方案", businessType = BusinessType.SELECT)
    @GetMapping("/getcatemodeltreehadgroup")
    public AjaxResult getcatemodeltreehadgroup(YqdacategoryModel yqdacategorymodel){
        return success(yqdacategoryModelService.getcatemodeltreehadgroup(yqdacategorymodel));
    }
    /**
     * 门类模板绑定元数据模板
     * @param id
     * @param groupId
     * @param wjcls
     * @param ajcls
     * @param xmcls
     * @param type
     */
    //@PreAuthorize("@ss.hasPermi('manage:MODEL:bind")
    @Log(title = "门类模板绑定元数据模板", businessType = BusinessType.UPDATE)
    @PostMapping("/bindgroup")
    public AjaxResult bindgroup(@RequestParam Long id, @RequestParam Long groupId, @RequestParam Integer wjcls, @RequestParam Integer ajcls, @RequestParam Integer xmcls, @RequestParam Integer type)
    {
        return toAjax(yqdacategoryModelService.bindgroup(id,groupId,wjcls,ajcls,xmcls,type));
    }
}
